package com.sykj.springboot.test.designMode.Observer4;

import com.sykj.springboot.common.utils.ClassUtils;

import java.util.List;
import java.util.Observer;

public class main {


    public static void main(String[] args) {
        /*Lisi lisi = new Lisi();
        Liusi liusi = new Liusi();

        Hanfeizi hanfeizi = new Hanfeizi();
        hanfeizi.addObserver(lisi);
        hanfeizi.addObserver(liusi);


        hanfeizi.haveBreakFast();
        hanfeizi.haveFun();*/


        try {
            //这种写法可以不用修改本方法，只需要增加观察类
            List<Class> allClassByInterface = ClassUtils.getAllClassByInterface(Observer.class,"com.sykj.springboot.test.designMode.Observer4");

            Hanfeizi hanfeizi = new Hanfeizi();
            for (Class cla:allClassByInterface) {
                Observer obs = (Observer)Class.forName(cla.getName()).newInstance();
                hanfeizi.addObserver(obs);
            }

            hanfeizi.haveBreakFast();
            hanfeizi.haveFun();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }





}
